﻿using System;
using System.Web;
using System.Web.SessionState;

namespace com.km.library {
    /// <summary>
    /// 存储当前会话的全局信息
    /// </summary>
    /// 
    public abstract class UserInfo 
    {
        /// <summary>
        /// 
        /// </summary>
        protected static HttpSessionState Session => HttpContext.Current != null ? HttpContext.Current.Session : null;

        //public static string OpenID {
        //    get { return Session["OpenID"] as string; }
        //    set { Session["OpenID"] = value; }
        //}
        /// <summary>
        /// 用户ID.
        /// </summary>
        public static int UserID {
            get {
                try
                {
                    return (int)Session["UserID"];
                }
                catch (Exception ex) { return 0; } 
                
            }
            set {
                Session["UserID"] = value;
            }
        }

        public static int CusIDInt {
            get {
                try {
                    return (int)Session["UserID"];
                } catch (Exception) {
                    return 0;
                }
            }
            set {
                Session["UserID"] = value;
            }
        }
        public static bool OneClickTrade {
            get {
                return (bool)Session["OneClickTrade"];
            }
            set {
                Session["OneClickTrade"] = value;
            }
        }
        /// <summary>
        /// 是否测试用户
        /// </summary>
        public static bool IsTestUser {
            get {
                if (Session["IsTestUser"] == null)
                    return false;
                try {
                    return (bool)Session["IsTestUser"];
                } catch (Exception) {
                    return false;
                }
            }
            set {
                Session["IsTestUser"] = value;
            }
        }
        /// <summary>
        /// 登录名.
        /// </summary>
        public static string UserCode {
            get {
                return Session["UserCode"] as string;
            }
            set {
                Session["UserCode"] = value;
            }
        }

        /// <summary>
        /// 用户头像.
        /// </summary>
        public static string UserImg
        {
            get {
                return Session["UserImg"] as string;
            }
            set {
                Session["UserImg"] = value;
            }
        }

        /// <summary>
        /// 用户名称.
        /// </summary>
        public static string UserName {
            get {
                return Session["UserName"] as string;
            }
            set {
                Session["UserName"] = value;
            }
        }
        /// <summary>
        /// 用户等级.
        /// </summary>
        public static string CusType {
            get {
                return Session["CusType"] as string;
            }
            set {
                Session["CusType"] = value;
            }
        }

        /// <summary>
        /// 用户类型.company,person,admin
        /// </summary>
        public static string UserType {
            get {
                return Session["UserType"] as string;
            }
            set {
                Session["UserType"] = value;
            }
        }

        /// <summary>
        /// 当前用户所属的部门
        /// </summary>
        public static string DeptNo {
            get {
                return Session["DeptNo"] as string;
            }
            set {
                Session["DeptNo"] = value;
            }
        }

        public static string AnonymousId
        {
            get { return Session["AnonymousId"] as string; }
            set { Session["AnonymousId"] = value; }
        }
    }
}
